<?php
/**
 * Created by PhpStorm.
 * User: liuhong
 * Date: 2018/11/12
 * Time: 下午2:25
 */

namespace Api\Service;


class AddressService extends BaseService
{
    protected $addressModel;
    public function __construct()
    {
        $this->addressModel=M('address');
    }

    /**
     * 新增收货地址
     * @param $addInfo
     * @return mixed
     */
    public function add($addInfo){
       return $this->addressModel->add($addInfo);
    }



    /**
     * 根据条件查询出地址信息
     * @param $where
     * @param $filed
     * @return mixed
     */
    public function findAddByWhere($where,$filed=null){
        if(empty($filed)){
            return $this->addressModel->where($where)->find();
        }else{
            return $this->addressModel->field($filed)->where($where)->find();
        }

    }


    /**
     * 条件查询出地址信息
     * @param $where
     * @param null $filed
     * @return mixed
     */
    public function selectAddByWhere($where,$filed=null){
        if(empty($filed)){
            return $this->addressModel->where($where)->select();
        }else{
            return $this->addressModel->field($filed)->where($where)->select();
        }
    }

    /**
     * 修改收货地址信息
     * @param $where
     * @param $save
     * @return bool
     */
    public function saveAddress($where,$save){
        return $this->addressModel->where($where)->save($save);
    }

    /**
     * 删除收货地址信息
     * @param $id
     * @return mixed
     */
    public function delAddress($id){
        return $this->addressModel->where(array('id'=>$id))->delete();
    }

    /**
     * 查询省份信息
     * @param $where
     * @return mixed
     */
    public function selectArea($where){
        $areaModel=M('area');
        return  $areaModel->field('area_id,parentid,area_name,level')->where($where)->select();
    }

    /**
     * 查询省份信息
     * @param $filed
     * @param $where
     * @return mixed
     */
    public function findArea($where,$filed=null){
        $areaModel=M('area');
        if(!empty($filed)){
            return  $areaModel->field('area_id,parentid,area_name,level')->where($where)->find();
        }else{
            return  $areaModel->field($filed)->where($where)->find();
        }

    }

}